import http from './http.js'

// 对话相关API
export const conversationApi = {
  // 获取用户收藏的会话
  getCollectedConversations(userId) {
    return http.get(`/api/conversations/user/${userId}/collected`)
  },

  // 获取所有对话
  getAllConversations() {
    return http.get('/api/conversations')
  },

  // 分页获取所有对话
  getAllConversationsPaged(page = 1, pageSize = 12) {
    return http.get(`/api/conversations/paged?page=${page}&pageSize=${pageSize}`)
  },

  // 根据ID获取对话
  getConversationById(id) {
    return http.get(`/api/conversations/${id}`)
  },

  // 根据用户ID获取对话列表
  getConversationsByUserId(userId) {
    return http.get(`/api/conversations/user/${userId}`)
  },

  // 分页获取用户对话列表
  getConversationsByUserIdPaged(userId, page = 1, pageSize = 12) {
    return http.get(`/api/conversations/user/${userId}/paged?page=${page}&pageSize=${pageSize}`)
  },

  // 根据标题搜索对话
  searchConversationsByTitle(title) {
    return http.get(`/api/conversations/search/title/${title}`)
  },

  // 创建新对话
  createConversation(conversationData) {
    return http.post('/api/conversations', conversationData)
  },

  // 更新对话
  updateConversation(id, conversationData) {
    return http.put(`/api/conversations/${id}`, conversationData)
  },

  // 删除对话
  deleteConversation(id) {
    return http.delete(`/api/conversations/${id}`)
  },

  // 收藏对话
  favoriteConversation(id) {
    return http.post(`/api/conversations/${id}/favorite`)
  },

  // 取消收藏对话
  unfavoriteConversation(id) {
    return http.delete(`/api/conversations/${id}/favorite`)
  },

  // 获取对话统计信息
  getConversationStats() {
    return http.get('/api/conversations/stats')
  }
}

// 消息相关API
export const messageApi = {
  // 获取对话中的所有消息
  getMessagesByConversationId(conversationId) {
    return http.get(`/api/messages/conversation/${conversationId}`)
  },

  // 根据ID获取消息
  getMessageById(id) {
    return http.get(`/api/messages/${id}`)
  },

  // 创建新消息
  createMessage(messageData) {
    return http.post('/api/messages', messageData)
  },

  // 更新消息
  updateMessage(id, messageData) {
    return http.put(`/api/messages/${id}`, messageData)
  },

  // 删除消息
  deleteMessage(id) {
    return http.delete(`/api/messages/${id}`)
  },

  // 根据发送者获取消息
  getMessagesBySender(senderId) {
    return http.get(`/api/messages/sender/${senderId}`)
  }
}

// 聊天相关API
export const chatApi = {
  // 发送聊天消息
  sendMessage(messageData) {
    return http.post('/api/chat/send', messageData)
  },

  // 获取聊天历史
  getChatHistory(conversationId, limit = 50) {
    return http.get(`/api/chat/history/${conversationId}?limit=${limit}`)
  }
}
